{extends 'admin/layout/main.tpl'}

{block title}管理员管理{/block}
{block smallTitle}系统内的管理员管理。{/block}

{block breadcrumb}
<li>管理员管理</li>
<li><a href="{route('AdminAdminList')}">管理员管理</a></li>
{/block}

{block main}
<div class="row">
	<div class="col-lg-12">
		<section class="panel">
			<header class="panel-heading">
                管理员列表
                {*<span class="tools pull-right">*}
                    {*<a href="{route('AdminAdminEdit')}" class="fa fa-plus">创建</a>*}
                {*</span>*}
            </header>
			<br>
            <a class="btn btn-info btn-xs" href="{route('AdminAdminEdit')}" ><i class="fa fa-plus"></i> 新增</a>
			<a class="btn btn-info btn-xs" href="javascript:;" onclick="post(3)"><i class="fa fa-edit"></i> 删除</a>
			<table class="table table-striped table-hover">
				<thead>
					<tr>
						<th><input type=checkbox onclick=sel(this)>&nbsp&nbsp#</th>
						<th>用户名</th>
						<th>创建时间</th>
						<th></th>
					</tr>
				</thead>
				<tbody>
				{foreach $data as $item}
					<tr data-ids="{$item.id}" data-name="{$item.name|escape}" data-type="3" data-from="admin">
						<td><input name="m" type=checkbox value="{$item.id}">&nbsp&nbsp{$item.id}</td>
						<td>{$item.username|escape}</td>
						<td>{$item.created_at}</td>
						<td>
							<a class="btn btn-xs btn-info" href="{route('AdminAdminEdit', ['id'=>$item.id])}"><i class="fa fa-edit"></i> 编辑</a>
							<button class="btn btn-xs btn-danger {if $item.username eq 'root'}disabled{/if}" type="button" {if $item.username neq 'root'}data-role="delete"{/if}><i class="fa fa-trash-o"></i> 删除</button>
						</td>
					</tr>
				{/foreach}
				</tbody>
			</table>
			{include 'admin/layout/paginate.tpl'}
		</section>
	</div>
</div>
{/block}

{block script}
<script>
	function sel(o)
	{
		var a = document.getElementsByName("m");
		for (var i=0;i<a.length;i++){
			a[i].checked = o.checked;
		}
	}

	function post(e){
		var compatibility = "",
				input = document.getElementsByName("m"),
				value;
		for (var i = 0; i < input.length; i++) {
			if (input[i].type == "checkbox") {
				if (input[i].checked) {
					value = input[i].value;
					compatibility += value + ",";
				}
			}
		}
        var data = { };
        data.from = 'admin';
        data.ids = compatibility;
        data.type = e;
		iconfirm({
			action	: '{route('AdminGlobalInfoEdit')}',
			body		: '确定要执行此操作吗？',
			data		: data
		});
		return false;
	}

	$('[data-role="delete"]').on('click', function(){
		var data = $(this).parents('tr').data();
		iconfirm({
			action	: '{route('AdminGlobalInfoEdit')}',
			body		: '确定要删除管理员 ' + data.name + ' 吗？',
			data		: data
		});
		return false;
	});
</script>
{/block}
